package com.hzqy.persistence.dao.content;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.hzqy.persistence.dao.core.PersistenceDao;
import com.hzqy.web.vo.CmCatalogVo;
import com.hzqy.web.vo.CmContentVo;
import com.hzqy.web.vo.UserHistoryVo;

@Repository
public class ContentDao extends PersistenceDao<CmContentVo,Integer> {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());

	public Integer updateContentCodeByName(CmContentVo cmCententVo) {
		return getSqlSession().update(this.getNamespace() + "updateContentCodeByName", cmCententVo);
	}
	public Integer updateContentSearchName(CmContentVo cmCententVo) {
		return getSqlSession().update(this.getNamespace() + "updateContentSearchName", cmCententVo);
	}
	
	public List<CmContentVo> selectContentListByName(CmContentVo cmCententVo) {
		return getSqlSession().selectList(this.getNamespace() + "selectContentListByName", cmCententVo);
	}

	public List<CmContentVo> selectContentListByCatalogId(int id,String f_po_id,int pageNo,int pageSize,String f_cp_cprid,CmContentVo contentVo){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_catalog_id", id);
		map.put("f_cco_orgId", f_po_id);
		map.put("firstResult", pageNo);
		map.put("pageSize", pageSize);
		map.put("f_cp_cprid", f_cp_cprid);
		map.put("f_cc_searchname", contentVo.getF_cc_searchname());
		map.put("f_cc_screenwriter", contentVo.getF_cc_screenwriter());
		map.put("f_cc_viewindex", contentVo.getF_cc_viewindex());
		map.put("f_cc_director", contentVo.getF_cc_director());
		map.put("f_cc_name", contentVo.getF_cc_name());
		map.put("f_sa_id", contentVo.getF_sa_id());
		map.put("f_cc_actors", contentVo.getF_cc_actors());
		map.put("f_cc_type", contentVo.getF_cc_type());
		String sort_column=contentVo.getSort_column();
		if("".equals(sort_column)||sort_column==null||"undefined".equals(sort_column)){
			contentVo.setSort_column("f_ccc_viewindex desc, f_cc_id desc");
		}
		map.put("sort_column", contentVo.getSort_column());
		return getSqlSession().selectList(this.getNamespace() + "selectContentListByCourse", map);
	}
	public List<CmContentVo> selectHistoryCourse(String courseType) {
		return getSqlSession().selectList(this.getNamespace() + "selectHistoryCourse", courseType);
	}
	public List<UserHistoryVo> selectUserViewHistory(String serverId) {
		return getSqlSession().selectList(this.getNamespace() + "selectUserViewHistory", serverId);
	}
	public List<CmContentVo> selectContentGroupByCourseList(int id,String f_po_id,int pageNo,int pageSize,CmContentVo contentVo) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_catalog_id", id);
		map.put("f_cco_orgId", f_po_id);
		map.put("firstResult", pageNo);
		map.put("pageSize", pageSize);
		map.put("f_cc_searchname", contentVo.getF_cc_searchname());
		map.put("f_cc_screenwriter", contentVo.getF_cc_screenwriter());
		map.put("f_cc_viewindex", contentVo.getF_cc_viewindex());
		map.put("f_cc_director", contentVo.getF_cc_director());
		map.put("f_cc_name", contentVo.getF_cc_name());
		map.put("f_sa_id", contentVo.getF_sa_id());
		map.put("f_cc_actors", contentVo.getF_cc_actors());
		map.put("f_cc_type", contentVo.getF_cc_type());
		System.out.println(contentVo.getF_cc_searchname());
		System.out.println(map.toString());
		return getSqlSession().selectList(this.getNamespace() + "selectContentGroupByCourseList", map);
	}
	public int selectContentGroupByCourseListCount(int id, String f_po_id, CmContentVo contentVo) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_catalog_id", id);
		map.put("f_cco_orgId", f_po_id);
		map.put("f_cc_searchname", contentVo.getF_cc_searchname());
		map.put("f_cc_screenwriter", contentVo.getF_cc_screenwriter());
		map.put("f_cc_viewindex", contentVo.getF_cc_viewindex());
		map.put("f_cc_director", contentVo.getF_cc_director());
		map.put("f_cc_name", contentVo.getF_cc_name());
		map.put("f_sa_id", contentVo.getF_sa_id());
		map.put("f_cc_actors", contentVo.getF_cc_actors());
		map.put("f_cc_type", contentVo.getF_cc_type());
		return getSqlSession().selectOne(this.getNamespace() + "selectContentGroupByCourseListCount", map);
	}
	public Integer selectContentListByCourseCount(int id, String f_po_id, CmContentVo contentVo) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_catalog_id", id);
		map.put("f_cco_orgId", f_po_id);
		map.put("f_cc_searchname", contentVo.getF_cc_searchname());
		map.put("f_cc_screenwriter", contentVo.getF_cc_screenwriter());
		map.put("f_cc_viewindex", contentVo.getF_cc_viewindex());
		map.put("f_cc_director", contentVo.getF_cc_director());
		map.put("f_cc_name", contentVo.getF_cc_name());
		map.put("f_sa_id", contentVo.getF_sa_id());
		map.put("f_cc_actors", contentVo.getF_cc_actors());
		map.put("f_cc_type", contentVo.getF_cc_type());
		Integer count=getSqlSession().selectOne(this.getNamespace() + "selectContentListByCourseCount", map);
		if(count==null){
			count=0;
		}
		return count;
	}

}
